<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "term_course".
 *
 * @property int $ID ID
 * @property int $XQID 学期ID
 * @property int $KCID 课程ID
 *
 * @property CourseTeacher[] $courseTeachers
 * @property Term $xQ
 * @property Course $kC
 */
class TermCourse extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'term_course';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['XQID', 'KCID'], 'required'],
            [['XQID', 'KCID'], 'integer'],
            [['XQID', 'KCID'], 'unique', 'targetAttribute' => ['XQID', 'KCID']],
            [['XQID'], 'exist', 'skipOnError' => true, 'targetClass' => Term::className(), 'targetAttribute' => ['XQID' => 'id']],
            [['KCID'], 'exist', 'skipOnError' => true, 'targetClass' => Course::className(), 'targetAttribute' => ['KCID' => 'ID']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'ID' => 'ID',
            'XQID' => '学期ID',
            'KCID' => '课程ID',
        ];
    }

    /**
     * Gets query for [[CourseTeachers]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getCourseTeachers()
    {
        return $this->hasMany(CourseTeacher::className(), ['KKID' => 'ID'])->inverseOf('kK');
    }

    /**
     * Gets query for [[XQ]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getXQ()
    {
        return $this->hasOne(Term::className(), ['id' => 'XQID'])->inverseOf('termCourses');
    }

    /**
     * Gets query for [[KC]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getKC()
    {
        return $this->hasOne(Course::className(), ['ID' => 'KCID'])->inverseOf('termCourses');
    }
}
